package com.kim.smartring.net.entity;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.util.Log;

import com.kim.smartring.db.model.User;
import com.kim.smartring.net.IReceiverListener;

public class LoginEntity extends BaseEntity {

	private static final String TAG = "LoginEntity";

	private String account;
	private String password;

	public LoginEntity(Context context, IReceiverListener receiverListener) {
		super(context, receiverListener);
	}

	public LoginEntity(Context context, User user,
			IReceiverListener receiverListener) {
		super(context, receiverListener);
		this.account = user.getAccount();
		this.password = user.getPassword();
	}

	@Override
	protected void init() {
		this.url = URLConstant.URL_LOGIN;
	}

	@Override
	public String getSendData() {
		return generateSendData();
	}

	private String generateSendData() {
		JSONObject jsonObject = new JSONObject();
		String sendData = null;
		try {
			jsonObject.put("account", account);
			jsonObject.put("password", password);
			sendData = jsonObject.toString();
			Log.d(TAG, String.format("login send data:%s", sendData));
		} catch (JSONException e) {
			e.printStackTrace();
		} finally {
			jsonObject = null;
		}
		return sendData;
	}

	/*
	 * { 　　“account”:”kim”, 　　“password”:”1234567” }
	 */
}
